package nl.science.uva.pico.operator;

import nl.science.uva.pico.Stack;
import nl.science.uva.pico.operand.Operand;

/** 
 * Count returns the length of the stack. 
 * 
 * @author Ivo van Dongen, Karel Pieterson
 * @version 1.0
 */
public class Count extends Operator {

    /** 
     * Calculates the size of the stack 
     * 
     * @param stack program stack of which the length needs to be calculated
     * 
     */
	public Count(Stack stack) {
		super(stack, null, null);
	}
    /** 
     * Count This instruction pushes the current stack size on top of the stack.
     * 
     * <p>perform pushes the length of the stack on the stack
     * <p>uses the stack push operator.
     * <p>Stack size is actually 1 larger then calculated after this operation!
     *  
     */
	@Override
	public void perform() {
		getStack().push(new Operand(getStack().size()));
	}

}
